import { IQuestion } from "@/model/question";

export interface IQuestionGenner {
  gen():IQuestion
}

export class GussBigQuestionGenner implements IQuestionGenner{
  gen(): IQuestion {
    const _raw = Math.floor(Math.random() * 10000)
    return {
       question: String(_raw)
    }
  }
}


export class GussNumQuestionGenner implements IQuestionGenner {
  gen(): IQuestion {
    const _raw:number[] = []
    for(let i = 0; i < 4;i++){
      let _current = this.getCurrent()

      // 去重
      while (_raw.findIndex(value => {
        return value === _current
      }) != -1) {
        _current = this.getCurrent()
      }
      _raw.push(_current)
    }

    return {
        question: _raw.join("")
    }
  }

  private getCurrent() {
    return Math.floor(Math.random() * 10);
  }
}
